﻿; (function (window, undefined, $) {
    var submiting = false;
    $('#frmEdit').validator({
        rules: {
            // 自定义规则，如果通过返回true，否则返回错误消息
            //cusidcard: function (element, param, field) {
            //    var idtype = $("#Id").val();
            //    if (idtype == param[0]) {
            //        return /^.+$/.test($(element).val()) || "必填项";
            //    }
            //    return true;
            //}
        },
        fields: {
            //'#ProjectNo': 'required',
            //'#ProjectName': 'required',
            //'#ProjectContent': 'required',
            //'#TotalLoan': 'required',
            //'#AnnualisedRates': 'required',
            //'#EnterpriseID': 'required',
            //'#EnterpriseAgent': 'required',
            //'#ProjectLocation': 'required',
            //'#RepaymentPlanDate': 'required',
            //'#BiddingDeadline': 'required',
            //'#LoanPurpose': 'required',
            //'#RepaymentSource': 'required',
            //'#LoanType': 'required',
            //'#AuditStatus': 'required',
            //'#LoanStatus': 'required',
            //'#RepaymentStatus': 'required',
            //'#CreateTime': 'required',
            //'#CreateUser': 'required',
            //'#AuditTime': 'required',
            //'#AuditUser': 'required',
            //'#LoanTime': 'required',
            //'#LoanUser': 'required',
            //'#RepaymentTime': 'required',
            //'#RepaymentUser': 'required',
        },
        valid: function (form) {
            if (submiting) {
                return;
            }
            submiting = true;
            FormSubmit(form, function (res) {
                if (res.Status > 0) {
                    alert("操作成功！");
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);

                }
                else {
                    alert("操作失败！");
                }
                submiting = false;
            })
        }
    });


    $("#btnSave").click(function (e) {
        $("#frmEdit").submit();
    });
    $("#btnReturn").click(function (e) {
        window.location.href = "/Project/Project.html";
    });
    $("#btnClose").click(function (e) {
        var url = "/Home/Index.html";
        location.href = url;
    });
    util.GetEnterpriseName = function (id) {
        $.layer({
            type: 2,
            shade: [0],
            fix: false,
            title: '预约信息',
            maxmin: false,
            iframe: { src: options.enterpriseUrl },
            area: ['800px', '440px'],
            close: function (index) {
                //子窗口返回值 layer.getChildFrame('#name', index).val()
                //layer.msg('您获得了子窗口标记：' + layer.getChildFrame('#name', index).val(), 3, 1);
            }
        });

    };

    util.GetPrompt = function (id, Input) {
        var Prompt = Input;
        if (Prompt != null && Prompt != "") {
            $.ajax({
                type: 'POST',
                url: '/Project/GetPrompt.html',
                data: { 'EnterpriseName': Prompt },
                dataType: 'json',
                success: function (data) {
                    var html = "";
                    if (data != null) {
                        for (var i = 0; i < data.length; i++) {
                            html += "<li id='" + i + "' onclick=\"util.GetVal('" + data[i].EnterpriseName + "')\" data-key='" + data[i].EnterpriseName + "' class='bdsug-store bdsug-overflow'><span>" + data[i].EnterpriseName + "</span></li>";
                        }
                    }
                    $('.bdsug ul').html(html);
                }
            })
            $('.bdsug').show();
        }
    };

    $("#EnterpriseName").autocomplete({
        source: function (request, response) {
            //$.getJSON('/Project/GetPrompt.html', { q: request.term}, function (res) {
            //    //if (res != null && res.status >= 0) {
            //    //    var str = eval("(" + res.data + ")");
            //    //    response(str);
            //    //}
            //    response(res);
            //});
            $.post('/Project/GetPrompt.html', { EnterpriseName: request.term },
                     function (res) {
                         var json = eval("(" + res.Data + ")");
                         response(json);
                     },
                     "json"
               );
        },
        select: function (e, ui) {
            document.location.href = "/Project/Enterprise.html/" + ui.item.id;
        }
    });


})(window, undefined, jQuery);